﻿@namespace BootstrapBlazor.Components
@typeparam TEnum where TEnum : Enum

<select @oninput="OnInput" @bind="@Value" class="form-control" disabled="@Disabled">
    @foreach (var t in typeof(TEnum).GetEnumNames())
    {
        <option value="@t">@t</option>
    }
</select>

@code {

    [Parameter] public TEnum Value { get; set; }
    [Parameter] public EventCallback<TEnum> ValueChanged { get; set; }
    [Parameter] public EventCallback<TEnum> OnValueChanged { get; set; }
    [Parameter] public bool Disabled { get; set; }

    async Task OnInput(ChangeEventArgs e)
    {
        var val = e.Value.ConvertTo<TEnum>();
        await OnValueChanged.InvokeAsync(val);
        await ValueChanged.InvokeAsync(val);
    }
}